﻿namespace MDXStudio
{
    using MDXParser;
    using Microsoft.AnalysisServices.AdomdClient;
    using System;

    internal class AdomdClientCubeInfo : MDXParser.CubeInfo
    {
        private AdomdConnection m_Cn;
        private string m_Cube;

        internal AdomdClientCubeInfo(string cubename, AdomdConnection cn)
        {
            this.m_Cube = cubename;
            this.m_Cn = cn;
        }

        public override MDXDataType DetermineType(string id)
        {
            if ((this.m_Cn != null) && (this.m_Cube != null))
            {
                DimensionCollection.Enumerator enumerator = this.m_Cn.Cubes[this.m_Cube].Dimensions.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Dimension current = enumerator.Current;
                    HierarchyCollection.Enumerator enumerator2 = current.Hierarchies.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        Hierarchy hierarchy = enumerator2.Current;
                        LevelCollection.Enumerator enumerator3 = hierarchy.Levels.GetEnumerator();
                        while (enumerator3.MoveNext())
                        {
                            Level level = enumerator3.Current;
                            if (id.Equals(level.UniqueName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                return MDXDataType.Level;
                            }
                        }
                        if (id.Equals(hierarchy.UniqueName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            return MDXDataType.Hierarchy;
                        }
                    }
                    if (id.Equals(current.UniqueName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return MDXDataType.Dimension;
                    }
                }
            }
            return base.DetermineType(id);
        }
    }
}

